<!--  -->
<template>
  <div class="report">
    <div class="report-radio">
      <el-radio-group v-model="reportState">
        <div class="radio-row">
          <el-radio :label="0">设置题目分数</el-radio>
          <el-radio :label="1" style="margin-left:10px">忽略题目分值</el-radio>
        </div>
      </el-radio-group>
    </div>
    <template v-if="reportState === 0">
      <el-card class="box-card1">
        <div slot="header" class="clearfix1">
          <span>题分设置</span>
          <div class="totalSorce">
            当前总分:{{ scoreTotal }}
          </div>
        </div>
        <el-table
          :data="setScore"
          border
          fit
          highlight-current-row
        >
          <el-table-column label="题目">
            <template slot-scope="scope">{{
              scope.row.question_content
            }}</template>
          </el-table-column>
          <el-table-column label="类型" width="80" align="center">
            <template slot-scope="scope">
              <template v-if="scope.row.question_case == 1">单选</template>
              <template v-else-if="scope.row.question_case == 2">多选</template>
              <template v-else>填空</template>
            </template>
          </el-table-column>
          <el-table-column label="计分方式" align="center" width="220">
            <template slot-scope="scope">
              <el-select
                v-model="scope.row.more_option_type"
                placeholder="请选择"
              >
                <template v-if="scope.row.question_case == 1">
                  <el-option
                    v-for="item in singleOptions"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  />
                </template>
                <template v-if="scope.row.question_case == 2">
                  <el-option
                    v-for="item in multOptions"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  />
                </template>
                <template v-if="scope.row.question_case == 3">
                  <el-option
                    v-for="item in fillBlankOption"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  />
                </template>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column label="设置答案" width="250">
            <template slot-scope="scope">
              <template v-if="scope.row.question_case == 1">
                <el-radio-group v-model="scope.row.singleRightIndex">
                  <div v-if="scope.row.more_option_type == 1" class="colunm">
                    <el-radio
                      v-for="(item, index) in scope.row.options"
                      :key="index"
                      :label="index"
                    >{{ item.is_other == 1 ? '其他':item.option_content }}</el-radio>
                  </div>
                </el-radio-group>
                <div v-if="scope.row.more_option_type == 2" class="colunm">
                  <div v-for="(item, index) in scope.row.options" :key="index">
                    {{ item.is_other == 1 ? '其他':item.option_content }}
                  </div>
                </div>
              </template>
              <template v-if="scope.row.question_case == 2">
                <div
                  v-if="
                    scope.row.more_option_type == 1 ||
                      scope.row.more_option_type == 2
                  "
                  class="colunm"
                >
                  <el-checkbox-group v-model="scope.row.multRightIndex">
                    <el-checkbox
                      v-for="(item, index) in scope.row.options"
                      :key="index"
                      :label="index"
                    >{{ item.is_other == 1 ? '其他':item.option_content }}</el-checkbox>
                  </el-checkbox-group>
                </div>
                <div v-if="scope.row.more_option_type == 3" class="colunm">
                  <div v-for="(item, index) in scope.row.options" :key="index">
                    {{ item.is_other == 1 ? '其他':item.option_content }}
                  </div>
                </div>
              </template>
              <template v-if="scope.row.question_case == 3">
                <div class="colunm">
                  <div
                    v-for="(item, index) in scope.row.options"
                    :key="index"
                    class="row"
                  >
                    <div class="optionName">答案{{ index + 1 }}:</div>
                    <el-input
                      v-model="item.option_content"
                      placeholder="请输入答案"
                      type="text"
                      style="width: 75%; margin-left: 15px"
                    />
                  </div>
                </div>
              </template>
            </template>
          </el-table-column>
          <el-table-column label="各选项分值" align="center" width="250">
            <template slot-scope="scope">
              <template v-if="scope.row.question_case == 1">
                <div v-if="scope.row.more_option_type == 1">
                  <template v-if="scope.row.singleRightIndex == -1">
                    <el-input
                      v-model="
                        scope.row.options[0].option_score
                      "
                      placeholder="请输入分数"
                      type="number"
                      :min="0"
                      :max="100"
                    />
                  </template>
                  <template v-else>
                    <el-input
                      v-model="
                        scope.row.options[scope.row.singleRightIndex].option_score
                      "
                      placeholder="请输入分数"
                      type="number"
                      :min="0"
                      :max="100"
                    />
                  </template>

                </div>
                <div v-if="scope.row.more_option_type == 2" class="colunm">
                  <div
                    v-for="(item, index) in scope.row.options"
                    :key="index"
                    class="row"
                  >
                    <div class="optionName">选项{{ index + 1 }}:</div>
                    <el-input
                      v-model="item.option_score"
                      placeholder="请输入分数"
                      style="width: 65%; margin-left: 15px"
                      type="number"
                      :min="0"
                      :max="100"
                    />
                  </div>
                </div>
              </template>
              <template v-if="scope.row.question_case == 2">
                <div v-if="scope.row.more_option_type == 1">
                  <el-input
                    v-model="scope.row.multTotalScore"
                    placeholder="请输入分数"
                    type="number"
                    :min="0"
                    :max="100"
                  />
                </div>
                <div v-if="scope.row.more_option_type == 2" class="colunm">
                  <template v-if="scope.row.multRightIndex.length>0">
                    <div
                      v-for="(item, index) in scope.row.multRightIndex"
                      :key="index"
                      class="row"
                    >
                      <div class="optionName">选项{{ item + 1 }}:</div>
                      <el-input
                        v-model="scope.row.options[item].option_score"
                        style="width: 65%; margin-left: 15px"
                        placeholder="请输入分数"
                        type="number"
                        :min="0"
                        :max="100"
                      />
                    </div>
                  </template>
                  <template v-else>
                    <div
                      v-for="(item, index) in [0,1]"
                      :key="index"
                      class="row"
                    >
                      <div class="optionName">选项{{ item + 1 }}:</div>
                      <el-input
                        v-model="scope.row.options[item].option_score"
                        style="width: 65%; margin-left: 15px"
                        placeholder="请输入分数"
                        type="number"
                        :min="0"
                        :max="100"
                      />
                    </div>
                  </template>

                </div>
                <div v-if="scope.row.more_option_type == 3" class="colunm">
                  <div
                    v-for="(item, index) in scope.row.options"
                    :key="index"
                    class="row"
                  >
                    <div class="optionName">选项{{ index + 1 }}:</div>
                    <el-input
                      v-model="item.option_score"
                      placeholder="请输入分数"
                      type="number"
                      :min="0"
                      :max="100"
                      style="width: 65%; margin-left: 15px"
                    />
                  </div>
                </div>
              </template>
              <template v-if="scope.row.question_case == 3">
                <div
                  v-for="(item, index) in scope.row.options"
                  :key="index"
                  class="row"
                >
                  <div class="optionName">答案{{ index + 1 }}分值:</div>
                  <el-input
                    v-model="item.option_score"
                    placeholder="请输入分数"
                    type="number"
                    :min="0"
                    :max="100"
                    style="width: 60%; margin-left: 15px"
                  />
                </div>
              </template>
            </template>
          </el-table-column>
          <el-table-column
            fixed="right"
            label="设置分数"
            align="center"
            width="80"
          >
            <template slot-scope="scope">
              <template v-if="scope.row.question_case == 1">
                <template v-if="scope.row.singleRightIndex == -1">
                  <el-button
                    v-if="scope.row.more_option_type == 1"
                    :disabled="
                      true
                    "
                    size="mini"
                    type="primary"
                    @click="
                      setFraction(
                        scope.row,
                        scope.row.singleRightIndex,
                        scope.$index
                      )
                    "
                  >设置</el-button>
                </template>
                <template v-else>
                  <el-button
                    v-if="scope.row.more_option_type == 1"
                    :disabled="
                      scope.row.options[scope.row.singleRightIndex].option_score ==
                        0
                    "
                    size="mini"
                    type="primary"
                    @click="
                      setFraction(
                        scope.row,
                        scope.row.singleRightIndex,
                        scope.$index
                      )
                    "
                  >设置</el-button>
                </template>

                <el-button
                  v-if="scope.row.more_option_type == 2"
                  size="mini"
                  type="primary"
                  @click="setAllFraction(scope.row, scope.$index)"
                >设置</el-button>
              </template>
              <template v-if="scope.row.question_case == 2">
                <el-button
                  v-if="scope.row.more_option_type == 1"
                  :disabled="
                    scope.row.multTotalScore == 0 ||
                      scope.row.multRightIndex.length < 2
                  "
                  size="mini"
                  type="primary"
                  @click="
                    setFraction1(
                      scope.row,
                      scope.row.multRightIndex,
                      scope.$index,
                      scope.row.multTotalScore
                    )
                  "
                >设置</el-button>
                <el-button
                  v-if="scope.row.more_option_type == 2"
                  :disabled="scope.row.multRightIndex.length < 2"
                  size="mini"
                  type="primary"
                  @click="
                    setFraction2(
                      scope.row,
                      scope.$index,
                      scope.row.multRightIndex
                    )
                  "
                >设置</el-button>
                <el-button
                  v-if="scope.row.more_option_type == 3"
                  size="mini"
                  type="primary"
                  @click="setAllFraction(scope.row, scope.$index)"
                >设置</el-button>
              </template>
              <template v-if="scope.row.question_case == 3">
                <el-button
                  size="mini"
                  type="primary"
                  @click="setAllFraction2(scope.row, scope.$index)"
                >设置</el-button>
              </template>
            </template>
          </el-table-column>
        </el-table>
      </el-card>
      <el-card class="box-card2">
        <div slot="header" class="clearfix">
          <span>维度设置</span>
        </div>
        <div class="box-card2-content">
          <div class="content-left">
            <div class="title">
              <div class="title1">维度名称</div>
              <div class="title2">维度拉取</div>
            </div>
            <div
              v-for="(item, index) in dimensionLenght"
              :key="index"
              class="left-item"
            >
              <el-input v-model="addDimensionGroupList[index].dimensionName" type="text" style="width:40%;margin-left:25px" placeholder="请输入维度名称" />
              <div class="input2">
                <div>
                  <el-tag
                    v-for="(item2, index2) in addDimensionGroupList[index]
                      .checkList"
                    :key="index2"
                    type="success"
                    closable
                    @close="tagClose(index, item2, index2)"
                  >题目{{ item2 + 1 }}</el-tag>
                </div>
              </div>
              <img
                src="@/assets/setFraction_images/this.png"
                style="width: 25px; height: 25px; margin-left: 20px"
                @click="push(index)"
              >
              </el-input></div>
            <div class="operation">
              <div v-if="dimensionLenght<6" class="operation1">
                <div class="add" @click="addDimensionLenght">
                  <i
                    class="el-icon-plus"
                    style="color: #ffffff; font-size: 22px"
                  />
                </div>
              </div>
              <div v-if="dimensionLenght>3" class="operation2">
                <i
                  class="el-icon-delete-solid"
                  style="color: red; font-size: 38px"
                  @click="DelDimensionLenght"
                />
              </div>
            </div>
          </div>

          <div class="content-right-box">
            <div class="content-right">
              <div class="checkBox">
                <el-checkbox-group v-model="checkList">
                  <div v-for="(item, index) in setScore" :key="index">
                    <el-checkbox
                      v-if="!item.isCheck"
                      :label="index"
                      class="checkbox-item"
                      :disabled="item.question_score == 0 || item.isChecked"
                    >{{ item.question_content }}</el-checkbox>
                  </div>
                </el-checkbox-group>
              </div>
            </div>
          </div>
        </div>
        <el-button
          type="primary"
          plain
          style="margin-left:25px"
          @click="addDimensionGroup"
        >设置</el-button>
      </el-card>
      <div v-if="isShowLevel">

        <el-card class="box-card">
          <div slot="header" class="clearfix1">
            <span>添加级别名称</span>
            <div class="operation3">
              <div v-if="setlevelList[0].levelLenght < 5" class="operation4">
                <el-button type="primary" plain @click="addLevel()">增加级别</el-button>

              </div>
              <div v-if="setlevelList[0].levelLenght > 3" class="operation5">
                <el-button plain type="danger" @click="delLevel()">删除级别</el-button>
              </div>
            </div>
          </div>
          <div style="margin:0px 25px">
            <div v-for="(item,index) in setlevelList[0].levelLenght " :key="index" style="width:30%;margin-top:30px" class="text item">
              <el-input v-model="levelNameList[index].levelName" placeholder="请输级别名称" />
            </div>
            <el-button
              type="primary"
              plain
              style="margin:30px 0px;"
              @click="setlevelName"
            >导入级别名称</el-button>
          </div>

        </el-card>
        <el-card
          v-for="(item, index) in setlevelList"
          :key="index"
          class="box-card3"
        >
          <div slot="header" class="clearfix">
            <span>维度名称：{{ item.dimension }}</span>
          </div>
          <div class="box-card3-content">
            <div class="title">
              <div class="title1">级别名称</div>
              <div class="title2">分值区间</div>
              <div class="title3">级别评估</div>
            </div>
            <div
              v-for="(item1, index1) in item.levelLenght"
              :key="index1"
              class="item"
            >
              <div class="input1">
                <el-input
                  v-model="item.levelList[index1].rate"
                  :disabled="true"
                />
              </div>
              <div class="input2">
                <div class="input2-content">
                  <el-input-number
                    v-model="item.levelList[index1].lowest_score"
                    :disabled="true"
                    controls-position="right"
                    :controls="false"
                    :min="0"
                    :max="100"
                  />
                  <div class="separate">——</div>
                  <el-input-number
                    v-model="item.levelList[index1].highest_score"
                    controls-position="right"
                    :min="0"
                    :max="100"
                    :controls="false"
                    :disabled="index1 + 1 == item.levelLenght"
                    @change="changeHighestScore(index, index1)"
                  />
                </div>
              </div>
              <div class="input3">
                <el-input
                  v-model="item.levelList[index1].content"
                  placeholder="请输入级别评估"
                  type="textarea"
                  :rows="2"
                />
              </div>
            </div>

          </div>
        </el-card>
      </div>
      <el-button
        v-if="isShowSave"
        type="primary"
        plain
        style="margin-top: 20px; float: right"
        @click="addDimensionRateGroup1"
      >保存及提交</el-button>
    </template>
    <template v-else>
      <el-row>
        <el-col>
          <el-card shadow="always" class="el-card5">
            请在智测用户列表中，点击报告预览，添加简易报告内容！
          </el-card>
        </el-col>
      </el-row>
      <el-button
        type="primary"
        plain
        style="position:absolute;right: 60px;bottom: 0px;"
        @click="saveNdrepor"
      >保存及提交</el-button>
    </template>
  </div>
</template>

<script>
// 这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
// 例如：import 《组件名称》 from '《组件路径》';
import {
    addDimensionGroup,
    addDimensionRateGroup,
    getAlldimension
} from '@/api/dimension'
import { getQuestionInfos, addQuestionGroup, saveNoReport } from '@/api/question'
export default {
    // import引入的组件需要注入到对象中才能使用
    components: {},
    props: ['group_id'],
    data() {
    // 这里存放数据
        return {
            scoreTotal: 0,
            isShowSave: false, // 是否显示保存及提交
            dimensionLenght: 3, // 维度长度
            showDelDimension: false,
            checkList: [],
            levelNameList: [{
                levelName: ''
            }, {
                levelName: ''
            }, {
                levelName: ''
            }, {
                levelName: ''
            }, {
                levelName: ''
            }],
            dialogFormVisible: false, // 是否显示增加维度名弹框
            addDimensionGroupList: [
                {
                    unid: '',
                    dimensionName: '',
                    dimension: [],
                    totalSorce: 0,
                    checkList: [],
                    dimension_question: []
                },
                {
                    unid: '',
                    dimensionName: '',
                    dimension: [],
                    totalSorce: 0,
                    checkList: [],
                    dimension_question: []
                },
                {
                    unid: '',
                    dimensionName: '',
                    dimension: [],
                    totalSorce: 0,
                    checkList: [],
                    dimension_question: []
                },
                {
                    unid: '',
                    dimensionName: '',
                    dimension: [],
                    totalSorce: 0,
                    checkList: [],
                    dimension_question: []
                },
                {
                    unid: '',
                    dimensionName: '',
                    dimension: [],
                    totalSorce: 0,
                    checkList: [],
                    dimension_question: []
                },
                { unid: '',
                    dimensionName: '',
                    dimension: [],
                    totalSorce: 0,
                    checkList: [],
                    dimension_question: []
                }
            ], // 添加维度题组数组
            singleOptions: [
                {
                    value: 1,
                    label: '此题有唯一答案和分值'
                },
                {
                    value: 2,
                    label: '每个选项都有对应分值'
                }
            ],
            multOptions: [
                {
                    value: 1,
                    label: '全答对才得分'
                },
                {
                    value: 2,
                    label: '答对几项得几分，答错不得分'
                },
                {
                    value: 3,
                    label: '每个选项都有对应分值'
                }
            ],
            fillBlankOption: [
                {
                    value: 1,
                    label: '回答与答案完全相同才得分'
                },
                {
                    value: 2,
                    label: '回答中包含答案即可得分'
                }
            ],
            //   添加成功的维度列表
            successDimension: [],
            // 级别表
            isShowLevel: false, // 是否显示级别
            //    设置级别
            setlevelList: [],
            //   设置分数
            setScore: [],
            reportState: 0
        }
    },
    // 监听属性 类似于data概念
    computed: {},
    // 监控data中的数据变化
    watch: {},
    // 生命周期 - 创建完成（可以访问当前this实例）
    created() {

    // 获取维度信息
    },
    // 生命周期 - 挂载完成（可以访问DOM元素）
    mounted() {
    //   获取题表
        this.getQuestionList()
    },
    // 方法集合
    methods: {
        async getQuestionList() {
            await getQuestionInfos({
                group_id: this.group_id
            }).then((res) => {
                res.data.forEach((item, index) => {
                    console.log('最高分1111111111111', item)
                    if (!item.question_score || item.question_score == 0) {
                        this.setScore.push({
                            unid: item.unid,
                            group_id: this.group_id,
                            question_content: item.content,
                            question_score: 0,
                            more_option_type: 1,
                            question_case: item.question_case,
                            sort: 1,
                            isChecked: false,
                            singleRightIndex: -1, // 单选正确答案索引
                            multRightIndex: [], // 多选正确答案索引
                            multTotalScore: 0, // 多选题总分
                            options: item.options.map((item2) => {
                                return {
                                    unid: item2.unid,
                                    group_id: this.group_id,
                                    option_content: item2.option == 'null' ? '' : item2.option,
                                    option_score: 0,
                                    question_group_id: item2.question_id,
                                    sort: item2.sort,
                                    is_other: item2.is_other
                                }
                            })
                        })
                    } else {
                        if (item.question_case == 1 && item.more_option_type == 1) {
                            this.setScore.push({
                                unid: item.unid,
                                group_id: this.group_id,
                                question_content: item.content,
                                question_score: item.question_score,
                                more_option_type: Number(item.more_option_type),
                                question_case: item.question_case,
                                sort: 1,
                                isChecked: false,
                                singleRightIndex: item.options.findIndex(
                                    (value) => value.option_score > 0
                                ),
                                multRightIndex: [], // 多选正确答案索引
                                multTotalScore: 0, // 多选题总分
                                options: item.options.map((item2) => {
                                    return {
                                        unid: item2.unid,
                                        group_id: this.group_id,
                                        option_content: item2.option == 'null' ? '' : item2.option,
                                        option_score: item2.option_score,
                                        question_group_id: item2.question_id,
                                        sort: item2.sort,
                                        is_other: item2.is_other
                                    }
                                })
                            })
                        } else if (
                            item.question_case == 2 &&
              (Number(item.more_option_type == 1) ||
                Number(item.more_option_type == 2))
                        ) {
                            var multRightIndex = []
                            for (let i = 0; i < item.options.length; i++) {
                                if (item.options[i].option_score > 0) {
                                    multRightIndex.push(i)
                                }
                            }
                            this.setScore.push({
                                unid: item.unid,
                                group_id: this.group_id,
                                question_content: item.content,
                                question_score: item.question_score,
                                more_option_type: Number(item.more_option_type),
                                question_case: item.question_case,
                                sort: 1,
                                isChecked: false,
                                singleRightIndex: -1,
                                multRightIndex: multRightIndex, // 多选正确答案索引
                                multTotalScore: item.question_score, // 多选题总分
                                options: item.options.map((item2) => {
                                    return {
                                        unid: item2.unid,
                                        group_id: this.group_id,
                                        option_content: item2.option == 'null' ? '' : item2.option,
                                        option_score: item2.option_score,
                                        question_group_id: item2.question_id,
                                        sort: item2.sort,
                                        is_other: item2.is_other
                                    }
                                })
                            })
                        } else {
                            this.setScore.push({
                                unid: item.unid,
                                group_id: this.group_id,
                                question_content: item.content,
                                question_score: item.question_score,
                                more_option_type: Number(item.more_option_type),
                                question_case: item.question_case,
                                sort: 1,
                                isChecked: false,
                                singleRightIndex: -1, // 单选正确答案索引
                                multRightIndex: [], // 多选正确答案索引
                                multTotalScore: item.question_score, // 多选题总分
                                options: item.options.map((item2) => {
                                    return {
                                        unid: item2.unid,
                                        group_id: this.group_id,
                                        option_content: item2.option == 'null' ? '' : item2.option,
                                        option_score: item2.option_score,
                                        question_group_id: item2.question_id,
                                        sort: item2.sort,
                                        is_other: item2.is_other
                                    }
                                })
                            })
                        }
                    }
                })
                // this.setScore.reverse()
                this.totalScore()
                console.log('设置分数1111111111', this.setScore)
            })
            // 获取维度题组评级表
            await this.getAlldimensionlist()
        },
        // 设置一个分数
        setFraction(item, singleRightIndex, setIndex) {
            console.log('设置分数', item)
            for (let i = 0; i < item.options.length; i++) {
                if (item.options[i].option_score > 100) {
                    return this.$message.error('设置分数不能大于100')
                }
            }
            let option_score = 0
            item.options.map((item3, index3) => {
                option_score += Number(item3.option_score)
                return option_score
            })
            console.log('最高分', option_score)
            var fractionData = {
                unid: item.unid,
                group_id: item.group_id,
                question_content: item.question_content,
                question_score: option_score,
                more_option_type: item.more_option_type,
                question_case: item.question_case,
                sort: item.sort,
                options: item.options.map((item2, index2) => {
                    if (singleRightIndex != index2) {
                        item2.option_score = 0
                    }
                    return {
                        unid: item2.unid,
                        group_id: item2.group_id,
                        option_content: item2.option_content,
                        option_score: item2.option_score,
                        question_group_id: item2.question_group_id,
                        sort: item2.sort,
                        is_other: item2.is_other
                    }
                })
            }
            console.log('参数', fractionData)
            addQuestionGroup(fractionData).then((res) => {
                if (res.code === 200) {
                    this.$notify({
                        title: '成功',
                        message: '设置成功',
                        type: 'success'
                    })
                    this.setScore[setIndex].question_score = option_score
                    this.totalScore()
                }
            })
        },
        // 设置多选题分数
        setFraction1(item, multRightIndex, setIndex, multTotalScore) {
            for (let i = 0; i < multRightIndex.length; i++) {
                if (multRightIndex.includes(i)) {
                    continue
                }
                item.options[i].option_score = 0
            }
            var fractionData = {
                unid: item.unid,
                group_id: item.group_id,
                question_content: item.question_content,
                question_score: multTotalScore,
                more_option_type: item.more_option_type,
                question_case: item.question_case,
                sort: item.sort,
                options: item.options.map((item2, index2) => {
                    multRightIndex.forEach((item4, index4) => {
                        item.options[item4].option_score =
              item.multTotalScore / multRightIndex.length
                    })
                    return {
                        unid: item2.unid,
                        group_id: item2.group_id,
                        option_content: item2.option_content,
                        option_score: item2.option_score,
                        question_group_id: item2.question_group_id,
                        sort: item2.sort,
                        is_other: item2.is_other
                    }
                })
            }
            for (let i = 0; i < item.options.length; i++) {
                if (item.options[i].option_score > 100) {
                    return this.$message.error('设置分数不能大于100')
                }
            }
            console.log('参数', fractionData)
            addQuestionGroup(fractionData).then((res) => {
                if (res.code === 200) {
                    this.$notify({
                        title: '成功',
                        message: '设置成功',
                        type: 'success'
                    })
                    this.setScore[setIndex].question_score = multTotalScore
                    this.totalScore()
                }
            })
        },
        // 设置多选题分数
        setFraction2(item, setIndex, multRightIndex) {
            for (let i = 0; i < item.options.length; i++) {
                if (item.options[i].option_score > 100) {
                    return this.$message.error('设置分数不能大于100')
                }
            }
            let option_score = 0
            item.options.map((item3, index3) => {
                option_score += Number(item3.option_score)
                return option_score
            })
            for (let i = 0; i < multRightIndex.length; i++) {
                if (multRightIndex.includes(i)) {
                    continue
                }
                item.options[i].option_score = 0
            }
            var fractionData = {
                unid: item.unid,
                group_id: item.group_id,
                question_content: item.question_content,
                question_score: option_score,
                more_option_type: item.more_option_type,
                question_case: item.question_case,
                sort: item.sort,
                options: item.options.map((item2, index2) => {
                    return {
                        unid: item2.unid,
                        group_id: item2.group_id,
                        option_content: item2.option_content,
                        option_score: item2.option_score,
                        question_group_id: item2.question_group_id,
                        sort: item2.sort,
                        is_other: item2.is_other
                    }
                })
            }
            console.log('参数', fractionData)
            addQuestionGroup(fractionData).then((res) => {
                if (res.code === 200) {
                    option_score = 0
                    this.$notify({
                        title: '成功',
                        message: '设置成功',
                        type: 'success'
                    })
                    this.setScore[setIndex].question_score = option_score
                    this.totalScore()
                }
            })
        },
        setAllFraction(item, setIndex) {
            for (let i = 0; i < item.options.length; i++) {
                if (item.options[i].option_score > 100) {
                    return this.$message.error('设置分数不能大于100')
                }
            }
            let option_score = 0
            let isFill = false
            item.options.map((item3, index3) => {
                option_score += Number(item3.option_score)
                return option_score
            })
            item.options.forEach((item5, index5) => {
                if (item5.option_score != 0) {
                    isFill = true
                }
            })
            if (isFill) {
                console.log('最高分', option_score)
                var fractionData = {
                    unid: item.unid,
                    group_id: item.group_id,
                    question_content: item.question_content,
                    question_score: option_score,
                    more_option_type: item.more_option_type,
                    question_case: item.question_case,
                    sort: item.sort,
                    options: item.options.map((item2, index2) => {
                        return {
                            unid: item2.unid,
                            group_id: item2.group_id,
                            option_content: item2.option_content,
                            option_score: item2.option_score,
                            question_group_id: item2.question_group_id,
                            sort: item2.sort,
                            is_other: item2.is_other
                        }
                    })
                }
                console.log('参数', fractionData)
                addQuestionGroup(fractionData).then((res) => {
                    if (res.code === 200) {
                        this.$notify({
                            title: '成功',
                            message: '设置成功',
                            type: 'success'
                        })
                        console.log('索引下标', setIndex)
                        this.setScore[setIndex].question_score = option_score
                        this.totalScore()
                    }
                })
            } else {
                this.$message.error('分数需要至少一项不为0')
            }
        },
        setAllFraction2(item, setIndex) {
            for (let i = 0; i < item.options.length; i++) {
                if (item.options[i].option_score > 100) {
                    return this.$message.error('设置分数不能大于100')
                }
            }
            let option_score = 0
            let isFill = false
            let isFill2 = false
            item.options.map((item3, index3) => {
                option_score += Number(item3.option_score)
                return option_score
            })
            item.options.forEach((item5, index5) => {
                console.log('tem5.option_content', item5.option_content)
                if (item5.option_score == 0) {
                    isFill = false
                } else {
                    isFill = true
                }
            })
            item.options.forEach((item6, index6) => {
                console.log('item6.option_content', item6.option_content)
                if (item6.option_content == 'null' || item6.option_content == '') {
                    isFill2 = false
                } else {
                    isFill2 = true
                }
            })
            if (isFill && isFill2) {
                console.log('最高分', option_score)
                var fractionData = {
                    unid: item.unid,
                    group_id: item.group_id,
                    question_content: item.question_content,
                    question_score: option_score,
                    more_option_type: item.more_option_type,
                    question_case: item.question_case,
                    sort: item.sort,
                    options: item.options.map((item2, index2) => {
                        return {
                            unid: item2.unid,
                            group_id: item2.group_id,
                            option_content: item2.option_content,
                            option_score: item2.option_score,
                            question_group_id: item2.question_group_id,
                            sort: item2.sort,
                            is_other: item2.is_other
                        }
                    })
                }
                console.log('参数', fractionData)
                addQuestionGroup(fractionData).then((res) => {
                    if (res.code === 200) {
                        this.$notify({
                            title: '成功',
                            message: '设置成功',
                            type: 'success'
                        })
                        this.setScore[setIndex].question_score = option_score
                        this.totalScore()
                    }
                })
            } else {
                this.$message.error('答案不为能空且分数不能为0')
            }
        },
        // 增加维度长度
        addDimensionLenght() {
            this.dimensionLenght = this.dimensionLenght + 1
        },
        // 减少维度长度
        DelDimensionLenght() {
            this.addDimensionGroupList[this.dimensionLenght - 1].checkList.forEach(
                (item) => {
                    this.setScore[item].isChecked = false
                }
            )
            this.addDimensionGroupList[this.dimensionLenght - 1].dimension = []
            this.addDimensionGroupList[this.dimensionLenght - 1].unid = ''
            this.addDimensionGroupList[this.dimensionLenght - 1].checkList = []
            this.addDimensionGroupList[
                this.dimensionLenght - 1
            ].dimension_question = []
            this.dimensionLenght = this.dimensionLenght - 1
        },
        // 维度拉取题目
        push(index) {
            var itemData = []
            console.log('checkList', this.checkList)
            if (this.checkList.length == 0) {
                this.$message.error('还未选择题目')
            } else {
                for (let i = 0; i < this.checkList.length; i++) {
                    this.setScore[this.checkList[i]].isChecked = true
                    this.addDimensionGroupList[index].checkList.push(this.checkList[i])
                }
                this.addDimensionGroupList[index].totalSorce = 0 // for循环加分之前要清空一次，不会重复加分
                for (
                    let i = 0;
                    i < this.addDimensionGroupList[index].checkList.length;
                    i++
                ) {
                    itemData.push(
                        this.setScore[this.addDimensionGroupList[index].checkList[i]]
                    )
                    this.addDimensionGroupList[index].totalSorce += Number(this.setScore[this.addDimensionGroupList[index].checkList[i]].question_score)
                }
                this.addDimensionGroupList[index].dimension = itemData
                console.log('addDimensionGroupList1', this.addDimensionGroupList)
            }
            //  因为for完全部都重新加入，所以每次push完要清空
            this.checkList = []
        },
        // 删除标签
        tagClose(index, item2, index2) {
            this.addDimensionGroupList[index].checkList.splice(index2, 1)
            this.addDimensionGroupList[index].totalSorce = 0 // for循环加分之前要清空一次，不会重复加分
            for (
                let i = 0;
                i < this.addDimensionGroupList[index].checkList.length;
                i++
            ) {
                this.addDimensionGroupList[index].totalSorce += Number(this.setScore[this.addDimensionGroupList[index].checkList[i]].question_score)
            }
            this.setScore[item2].isChecked = false
            console.log('addDimensionGroupList2', this.addDimensionGroupList)
        },
        // 增加维度题组
        addDimensionGroup() {
            var isFill = true
            for (let i = 0; i < this.dimensionLenght; i++) {
                if (
                    this.addDimensionGroupList[i].dimensionName == '' ||
          this.addDimensionGroupList[i].checkList.length == 0
                ) {
                    isFill = false
                }
            }
            for (let i = 0; i < this.dimensionLenght - 1; i++) {
                for (let j = i + 1; j < this.dimensionLenght; j++) {
                    if (this.addDimensionGroupList[i].dimensionName === this.addDimensionGroupList[j].dimensionName) {
                        isFill = false
                    }
                }
            }
            if (isFill) {
                this.addDimensionGroupList.forEach((item, index) => {
                    this.addDimensionGroupList[index].dimension_question = []
                    item.checkList.forEach((item1, index1) => {
                        this.addDimensionGroupList[index].dimension_question.push(
                            this.setScore[item1].unid
                        )
                    })
                })
                var data = []
                for (let i = 0; i < this.dimensionLenght; i++) {
                    data.push({
                        unid: this.addDimensionGroupList[i].unid,
                        dimension: this.addDimensionGroupList[i].dimensionName,
                        group_id: this.group_id,
                        dimension_question: this.addDimensionGroupList[i]
                            .dimension_question,
                        score: this.addDimensionGroupList[i].totalSorce
                    })
                }
                var obj = {
                    dimension: data,
                    group_id: this.group_id
                }
                console.log('参数', obj)
                addDimensionGroup(obj).then((res) => {
                    if (res.code === 200) {
                        this.successDimension = res.data
                        this.$notify({
                            title: '成功',
                            message: '添加成功',
                            type: 'success'
                        })
                        this.isShowLevel = true
                        this.isShowSave = true
                        this.setlevelList = []

                        console.log('res.data', res.data)
                        for (let i = 0; i < this.dimensionLenght; i++) {
                            this.addDimensionGroupList[i].unid = res.data[i].unid
                        }
                        console.log('保存成功后的数组', this.addDimensionGroupList)
                        this.successDimension.forEach((item, index) => {
                            this.setlevelList.push({
                                dimension: item.dimension,
                                unid: item.unid,
                                levelLenght: 3, // 级别长度
                                levelList: [
                                    {
                                        content: '',
                                        lowest_score: 0,
                                        highest_score: 0,
                                        dimension_group_id: item.unid,
                                        rate: ''
                                    },
                                    {
                                        content: '',
                                        lowest_score: 0,
                                        highest_score: 0,
                                        dimension_group_id: item.unid,
                                        rate: ''
                                    },
                                    {
                                        content: '',
                                        lowest_score: 0,
                                        highest_score: 100,
                                        dimension_group_id: item.unid,
                                        rate: ''
                                    },
                                    {
                                        content: '',
                                        lowest_score: 0,
                                        highest_score: 0,
                                        dimension_group_id: item.unid,
                                        rate: ''
                                    },
                                    {
                                        content: '',
                                        lowest_score: 0,
                                        highest_score: 0,
                                        dimension_group_id: item.unid,
                                        rate: ''
                                    }
                                ]
                            })
                        })
                    }
                })
            } else {
                this.$message.error('还选项未填写或维度名称重复')
            }
        },
        // 题目分数
        totalScore() {
            let option_score = 0
            this.setScore.map((item3, index3) => {
                console.log('item3.question_score', item3.question_score)
                option_score += Number(item3.question_score)
                return option_score
            })
            this.scoreTotal = option_score
            console.log('题目总分', this.scoreTotal)
        },
        // 增加级别
        addLevel() {
            for (let i = 0; i < this.setlevelList.length; i++) {
                this.setlevelList[i].levelList[
                    this.setlevelList[i].levelLenght - 1
                ].highest_score = 0
                this.setlevelList[i].levelLenght =
        this.setlevelList[i].levelLenght + 1
                this.setlevelList[i].levelList[
                    this.setlevelList[i].levelLenght - 1
                ].highest_score = 100
            }
        },
        // 删除级别
        delLevel() {
            for (let i = 0; i < this.setlevelList.length; i++) {
                this.setlevelList[i].levelList[
                    this.setlevelList[i].levelLenght - 2
                ].highest_score = 100
                this.setlevelList[i].levelLenght =
        this.setlevelList[i].levelLenght - 1
                this.setlevelList[i].levelList[
                    this.setlevelList[i].levelLenght
                ].highest_score = 0
                this.setlevelList[i].levelList[
                    this.setlevelList[i].levelLenght
                ].rate = ''
                this.setlevelList[i].levelList[
                    this.setlevelList[i].levelLenght
                ].content = ''
                this.levelNameList[
                    this.setlevelList[i].levelLenght
                ].levelName = ''
            }
        },
        // 修改最低值
        changeHighestScore(index, index1) {
            if (
                this.setlevelList[index].levelList[index1].highest_score <
        this.setlevelList[index].levelList[index1].lowest_score
            ) {
                this.setlevelList[index].levelList[index1].highest_score =
        this.setlevelList[index].levelList[index1].lowest_score + 1
                this.$message.error('最高值不能小于最低值')
                this.setlevelList[index].levelList[index1 + 1].lowest_score =
        this.setlevelList[index].levelList[index1].highest_score + 1
                return
            }
            this.setlevelList[index].levelList[index1 + 1].lowest_score =
        this.setlevelList[index].levelList[index1].highest_score + 1
        },
        // 添加级别
        addDimensionRateGroup1() {
            console.log('级别', this.setlevelList)
            var dataList = []
            var isFill = true

            for (let i = 0; i < this.setlevelList.length; i++) {
                for (let j = 0; j < this.setlevelList[i].levelLenght; j++) {
                    if (
                        this.setlevelList[i].levelList[j].content == '' ||
            this.setlevelList[i].levelList[j].rate == '' ||
            this.setlevelList[i].levelList[j].highest_score == 0
                    ) {
                        isFill = false
                    } else {
                        if (this.setlevelList[i].levelList[j].lowest_score == 0 && j != 0) {
                            isFill = false
                        }
                    }
                }
            }
            console.log('isFill', isFill)
            if (isFill) {
                for (let i = 0; i < this.setlevelList.length; i++) {
                    for (let j = 0; j < this.setlevelList[i].levelLenght; j++) {
                        dataList.push(this.setlevelList[i].levelList[j])
                    }
                }
                var objData = {
                    dimension: dataList
                }
                console.log('参数', objData)
                addDimensionRateGroup(objData).then((res) => {
                    console.log('res', res)
                    if (res.code == 200) {
                        this.$notify({
                            title: '成功',
                            message: '设置成功',
                            type: 'success'
                        })
                        saveNoReport({
                            unid: this.group_id
                        }).then(res => {
                            if (res.code === 200) {
                                this.$store.dispatch('tagsView/delView', this.$route)
                                this.$router.replace('/intelligentTest')
                            }
                        })
                    } else {
                        this.$message.error('错误')
                    }
                })
            } else {
                this.$message.error('请完善信息')
            }
        },
        // 获取维度题组评级
        getAlldimensionlist() {
            console.log('group_id', this.group_id)
            getAlldimension({ group_id: this.group_id }).then((res) => {
                console.log('获取维度题组评级>>>>>>>', res.data)
                if (res.code == 200) {
                    if (res.data.length > 0) {
                        var addDimensionGroupList = []
                        var setlevelList = []
                        this.dimensionLenght = res.data.length
                        for (let i = 0; i < this.dimensionLenght; i++) {
                            var aaa = []
                            for (let j = 0; j < this.setScore.length; j++) {
                                if (
                                    res.data[i].dimension_question.includes(this.setScore[j].unid)
                                ) {
                                    aaa.push(j)
                                    console.log(aaa)
                                }
                            }
                            addDimensionGroupList.push({
                                unid: res.data[i].unid,
                                dimensionName: res.data[i].dimension,
                                checkList: aaa,
                                totalSorce: Number(res.data[i].score)

                            })

                            if (res.data[i].rate.length > 0) {
                                this.isShowLevel = true
                                this.isShowSave = true
                                setlevelList.push({
                                    dimension: res.data[i].dimension,
                                    unid: res.data[i].unid,
                                    levelLenght: res.data[i].rate.length, // 级别长度
                                    levelList: [
                                        {
                                            content: '',
                                            lowest_score: 0,
                                            highest_score: 0,
                                            dimension_group_id: res.data[i].unid,
                                            rate: ''
                                        },
                                        {
                                            content: '',
                                            lowest_score: 0,
                                            highest_score: 0,
                                            dimension_group_id: res.data[i].unid,
                                            rate: ''
                                        },
                                        {
                                            content: '',
                                            lowest_score: 0,
                                            highest_score: 100,
                                            dimension_group_id: res.data[i].unid,
                                            rate: ''
                                        },
                                        {
                                            content: '',
                                            lowest_score: 0,
                                            highest_score: 0,
                                            dimension_group_id: res.data[i].unid,
                                            rate: ''
                                        },
                                        {
                                            content: '',
                                            lowest_score: 0,
                                            highest_score: 0,
                                            dimension_group_id: res.data[i].unid,
                                            rate: ''
                                        }
                                    ]
                                })

                                for (let o = 0; o < res.data[i].rate.length; o++) {
                                    setlevelList[i].levelList[o].content =
                    res.data[i].rate[o].content
                                    setlevelList[i].levelList[o].lowest_score =
                    res.data[i].rate[o].lowest_score
                                    setlevelList[i].levelList[o].highest_score =
                    res.data[i].rate[o].highest_score
                                    setlevelList[i].levelList[o].rate = res.data[i].rate[o].rate
                                    this.levelNameList[o].levelName = res.data[i].rate[o].rate
                                }
                            }
                        }
                        for (let n = 0; n < this.dimensionLenght; n++) {
                            this.addDimensionGroupList[n].unid = addDimensionGroupList[n].unid
                            this.addDimensionGroupList[n].dimensionName = addDimensionGroupList[n].dimensionName
                            this.addDimensionGroupList[n].totalSorce = addDimensionGroupList[n].totalSorce
                            this.addDimensionGroupList[n].checkList = addDimensionGroupList[n].checkList
                            this.addDimensionGroupList[n].dimension = []
                            this.addDimensionGroupList[n].dimension_question = []
                        }
                        for (let m = 0; m < this.dimensionLenght; m++) {
                            for (
                                let j = 0;
                                j < this.addDimensionGroupList[m].checkList.length;
                                j++
                            ) {
                                this.setScore[
                                    this.addDimensionGroupList[m].checkList[j]
                                ].isChecked = true
                            }
                        }
                        this.setlevelList = setlevelList
                        console.log('级别', this.setlevelList)
                    }
                }
            })
        },
        // 设置级别名称
        setlevelName() {
            var isFill = true
            console.log('触发', this.setlevelList)
            for (let k = 0; k < this.setlevelList[0].levelLenght; k++) {
                if (this.levelNameList[k].levelName == '') {
                    isFill = false
                }
            }
            if (isFill) {
                for (let i = 0; i < this.setlevelList.length; i++) {
                    console.log('加入1', this.setlevelList)
                    for (let j = 0; j < this.setlevelList[i].levelLenght; j++) {
                        this.setlevelList[i].levelList[j].rate = this.levelNameList[j].levelName
                    }
                }
            } else {
                this.$message.error('还有级别名称未填写')
            }
        },
        // 没有分数设置的提交报告
        saveNdrepor() {
            saveNoReport({
                unid: this.group_id,
                status: 1
            }).then(res => {
                if (res.code === 200) {
                    this.$store.dispatch('tagsView/delView', this.$route)
                    this.$router.replace('/intelligentTest')
                }
            })
        }
    }
}
</script>
<style lang='scss' scoped>
//@import url(); 引入公共css类
.report {
  height: 100%;
  width: 100%;
// width: 1000px;
  .colunm {
    display: flex;
    flex-direction: column;
  }
  .row {
    display: flex;
    flex-direction: row;
    align-items: center;
    margin-top: 5px;
  }
  .el-radio {
    margin-top: 10px;
     margin-right: 0px;
  }

  .el-checkbox-group {
    display: flex;
    flex-direction: column;
    .el-checkbox{
        display: flex;
        align-items: flex-start;
      margin-right: 0px;
     }
  }

  .report-radio{
      display: flex;
      justify-content: flex-end;
      margin-bottom: 20px;
      .radio-row{
          display: flex;
          align-items: center;
      }
  }
}
.box-card2 {
  margin-top: 24px;
  min-height: 620px;

  .box-card2-content {
    display: flex;

    .content-left {
      flex: 2;
      display: flex;
      flex-direction: column;

      .title {
        display: flex;
        width: 100%;

        .title1 {
          width: 45%;
          text-align: center;
          font-size: 14px;
          font-weight: 400;
          line-height: 22px;
          color: rgba(0, 0, 0, 0.85);
          opacity: 1;
        }

        .title2 {
          width: 45%;
          text-align: center;
          font-size: 14px;
          font-weight: 400;
          line-height: 22px;
          color: rgba(0, 0, 0, 0.85);
          opacity: 1;
        }
      }
    }

    .content-right-box {
      flex: 1;
    }

    .content-right {
      width: 100%;
    }
  }
}

.left-item {
  display: flex;
  align-items: center;
  margin-top: 20px;

  .input1 {
    width: 40%;
  }

  .input2 {
    width: 40%;
    min-height: 40px;
    border-radius: 4px;
    border: 1px solid #dcdfe6;
    display: flex;
    align-items: center;
    margin-left: 40px;
  }

  .el-select {
    width: 40%;
    margin-left: 30px;
  }

  .el-button {
    padding: 0px;
  }
}

.content-right {
  .checkBox {
    overflow: auto;
    padding: 30px 24px;
    box-sizing: border-box;
    margin-left: 20px;
    width: 500px;
    height: 480px;
    background: #ffffff;
    box-shadow: 0px 2px 12px rgba(0, 0, 0, 0.1);
    opacity: 1;
    border-radius: 4px;
    .checkbox-item {
      margin-top: 20px;
      display: flex;
      align-items: flex-start;
    }
  }
}

.box-card3 {
  margin-top: 20px;
  padding-bottom: 20px;
  .box-card3-content {
    .title {
      display: flex;
      width: 100%;

      .title1 {
        flex: 1;
        text-align: center;
        font-size: 14px;
        font-weight: 400;
        line-height: 22px;
        color: rgba(0, 0, 0, 0.85);
        opacity: 1;
      }

      .title2 {
        flex: 1;
        text-align: center;
        font-size: 14px;
        font-weight: 400;
        line-height: 22px;
        color: rgba(0, 0, 0, 0.85);
        opacity: 1;
      }

      .title3 {
        flex: 1;
        text-align: center;
        font-size: 14px;
        font-weight: 400;
        line-height: 22px;
        color: rgba(0, 0, 0, 0.85);
        opacity: 1;
      }
    }

    .item {
      margin-top: 45px;
      display: flex;

      .input1 {
        flex: 1;
        text-align: center;

        .el-input {
          width: 80%;
        }
      }

      .input2 {
        flex: 1;
      }

      .input3 {
        flex: 1;
        text-align: center;

        .el-textarea {
          width: 80%;
        }
      }
    }
    .input2-content {
      width: 80%;
      display: flex;
      margin: 0 auto;
      align-items: center;
      .separate {
        color: #dcdfe6;
        padding: 0px 10px;
      }
    }
  }
}

.input2-content {
  width: 80%;
  display: flex;
  margin: 0 auto;
  align-items: center;

  .separate {
    color: #dcdfe6;
    padding: 0px 10px;

  }
}

.operation {
  display: flex;
  align-items: center;
  margin-left: 30px;
  margin-top: 20px;
  width: 40%;

  .operation1 {
    flex: 1;
    display: flex;
    justify-content: flex-start;
  }

  .operation2 {
    flex: 1;
    display: flex;
    justify-content: flex-start;
  }
}
.operation3 {
  display: flex;
  align-items: center;
  width: 20%;
  .operation4 {
    flex: 1;
    display: flex;
    justify-content: flex-end;
  }

  .operation5 {
    flex: 1;
    display: flex;
    justify-content: flex-end;
  }
}

.add {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #42b983;
  opacity: 1;
  border-radius: 4px;
}

.add1 {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #42b983;
  opacity: 1;
  border-radius: 4px;
  margin-left: 5px;
}

.totalSorce {
  padding: 10px;
  color: #ffffff;
  background: #42b983;
  font-size: 16px;
}

.el-tag {
  margin-left: 5px;
}
.clearfix1{
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.box-card{
    margin-top: 20px;
}
.el-card5{
    padding: 20px;
    text-align: center;
}
</style>
